package kr.hkit.powerjava.chapter10.Programming;

import java.util.Scanner;

public class Average {

	private int stuNum;
	private int[] scores;
	Scanner input;

	public Average(int stuNum) {
		this.stuNum = stuNum;
		scores = new int[stuNum];
	}

	public void setScores() {
		input = new Scanner(System.in);
		
		for (int i = 0; i < scores.length; i++) {
			scores[i] = checkScores(i);
		}
	}

	public int checkScores(int i) {
		System.out.print("학생 " + (i+1) + "의 성적을 입력하시오: ");
		int score = input.nextInt();
		
		while(score > 100 || score < 0) {
			System.out.println("잘못된 성적입니다. 다시 입력하시오.");
			System.out.print("학생 " + (i+1) + "의 성적을 입력하시오: ");
			score = input.nextInt();
		}
		return score;
	}
	
	public double makeAvg(){
		int sum = 0;
		double avg;
		for (int i = 0; i < scores.length; i++) {
			sum += scores[i];
		}
		
		avg = (double)sum / scores.length;
		
		return avg;
	}
}
